<template>
	<view>
		<uni-section title="搜索" type="line">
			<uni-search-bar @confirm="search" v-model="params.flowNum" @cancel="cancel" @clear="cancel">
			</uni-search-bar>
			<view class="uni-padding-wrap uni-common-mt">
				<uni-segmented-control :current="current" :values="items" 
				@clickItem="onClickItem"></uni-segmented-control>
			</view>
		</uni-section>
		
		<uni-section title="工单列表" type="line">
			<uni-list>
				<uni-list-item v-for="(item, i) in list" :key="i" show-arrow
					:title="item.flow.typeName + ' ' + item.flow.num" 
					:note="flowNote(item.flow)" clickable @click="clickFlow(item)"
					:rightText="item.flow.userName + ' ' + item.flow.applyTime">			
				</uni-list-item>
			</uni-list>
		</uni-section>
		<uni-load-more :status="moreStatus" @clickLoadMore="getList"/>
	</view>
</template>

<script>
	import {listMyCheck} from '@/api/flow.js'
	export default {
		components: {},
		data() {
			return {
				items: ['待审核', '审核通过', '未通过'],
				current: 0,
				list:[],
				moreStatus:'noMore',
				params:{
					checkStatus:'0',
					flowNum:null,
					pageSize: 10,
					pageNum: 1,
					orderByColumn: 't.id',
					isAsc: 'DESC'
				}
			}
		},
		onLoad() {
			this.getList();
		},
		onShow() {
			this.getList();
		},
		methods: {
			getList() {
				listMyCheck(this.params).then(response=>{
					if(response.rows == null || response.rows.length == 0){
						this.moreStatus = 'noMore';
					}
					if(this.params.pageNum == 1){
						this.list = response.rows;
					}else{
						this.list = this.list.concat(response.rows);
					}
					
					if(response.rows.length < this.params.pageSize){
						this.moreStatus = 'noMore';
					}else{						
						this.moreStatus = 'more';
						this.params.pageNum += 1;
					}
				})
			},
			onClickItem(e) {
				if(e.currentIndex == 0){
					this.params.checkStatus = '0';
				}else if(e.currentIndex == 1){
					this.params.checkStatus = '1';
				}else if(e.currentIndex == 2){
					this.params.checkStatus = '2';
				}
				this.list = [];
				this.params.pageNum = 1;
				this.getList();
			},
			flowNote(flow){
				if(flow.typeCode == 'purchase') {
					return '资产分类：' + flow.cateName + ', 数量：'+flow.amount + ', 单价：' + flow.price;
				}else{
					return '资产分类：' + flow.cateName + ', 编码：'+flow.assetNum;
				}
			},
			clickFlow(check) {
				if(check.checkStatus == '0'){					
					this.$tab.navigateTo('/pages/flow/step?action=check&id='+check.id);	
				}else{					
					this.$tab.navigateTo('/pages/flow/step?action=view&id='+check.id);	
				}
			},
			search(res) {
				this.params.pageNum = 1;
				this.list = [];
				this.getList();
			},
			cancel(res) {
				this.params.flowNum = null;
				this.search();
			}
		}
	}
</script>

<style>
	.uni-common-mt {
		margin-top: 10px;
	}

	.uni-padding-wrap {
		// width: 750rpx;
		padding: 0px 10px;
	}
</style>